# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html
import os.path

# useful for handling different item types with a single interface
from itemadapter import ItemAdapter


class BiqugePipeline:
    def process_item(self, item, spider):
        novel_path=f"{item['book_name']}//"
        if not os.path.exists(novel_path):
            os.mkdir(novel_path)
        title_path = os.path.join(novel_path,item['title']+".txt")
        with open(title_path,'w',encoding='utf-8') as f:
            f.write(item['title']+"\n")
            f.write(item['novel_content'])
        return item
